package huoye.shops.huoye.operation.presenter;


import android.util.Log;

import java.util.List;

import huoye.shops.base.BasePresenter;
import huoye.shops.base.MineBaseJsonRequestCallback;
import huoye.shops.common.model.OssImageData;
import huoye.shops.huoye.operation.model.OrderInfo;
import huoye.shops.huoye.operation.networt.OperationService;
import huoye.shops.huoye.operation.view.IEditAddShopView;
import huoye.shops.huoye.operation.view.IOrderDetailsView;
import huoye.shops.huoye.user.model.User;


/**
 * Created by uesr on 2017/7/19.
 */

public class EditAddShopPresenter extends BasePresenter<IEditAddShopView> {


    private OperationService mService;

    //
    public void savePrize(String prizeTitle,String prizeSale,String prizeNum,String prizeImg,int type){
        if(prizeTitle.equals("")){
            view.makeToast("请输入奖品名称");
            return;
        }else if(prizeSale.equals("")){
            view.makeToast("请输入奖品售价");
            return;
        }else if(prizeNum.equals("")){
            view.makeToast("请输入奖品库存");
            return;
        }else if(prizeNum.equals("0")){
            view.makeToast("库存必须大于0");
            return;
        }
        else if(prizeImg.equals("")){
            view.makeToast("请选择奖品封面");
            return;
        }else {
            //  view.showProcessingIndicator();
            mService.savePrize(prizeTitle,prizeSale,prizeNum,prizeImg,type,new MineBaseJsonRequestCallback<User>(User.class) {

                @Override
                public void onSuccess() {
                    super.onSuccess();
                    view.makeToast("上传奖品成功！");
                    view.finish();
                }

                //网络请求失败
                @Override
                public void onFailure(String msg, String code, Throwable e) {
                    super.onFailure(msg, code, e);
                    view.makeToast(msg);
                }

                //加载结束
                @Override
                public void onNetworkFail() {
                    super.onNetworkFail();
                    view.onNetworkFail();
                }

                //加载中
                @Override
                public void onFinish() {
                    super.onFinish();
                    view.hideProcessingIndicator();
                }
            });
        }
    }






    //图片上传
    public void uploadOssImg(String id,String type,String filePath){
        //  view.showProcessingIndicator();
            mService.uploadOssImg(id,type,filePath,new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

               @Override
                public void onSuccess(List<OssImageData> list) {
                    super.onSuccess(list);
                   Log.e("test",list.get(0).toString());
                   OssImageData ossImageData = list.get(0);
                   view.setUpload(ossImageData);
                }

                //网络请求失败
                @Override
                public void onFailure(String msg, String code, Throwable e) {
                    super.onFailure(msg, code, e);
                    view.makeToast(msg);
                }

                //加载结束
                @Override
                public void onNetworkFail() {
                    super.onNetworkFail();
                    view.onNetworkFail();
                }

                //加载中
                @Override
                public void onFinish() {
                    super.onFinish();
                    view.hideProcessingIndicator();
                }
            });

    }


    //图片删除
    public void deleteOssImg(String filePath){
        //  view.showProcessingIndicator();
        mService.deleteOssImg(filePath,new MineBaseJsonRequestCallback<OssImageData>(OssImageData.class) {

            @Override
            public void onSuccess() {
                super.onSuccess();
                //view.makeToast("OSS图片删除成功！");
                view.delUpload();
            }

            //网络请求失败
            @Override
            public void onFailure(String msg, String code, Throwable e) {
                super.onFailure(msg, code, e);
                view.makeToast(msg);
            }

            //加载结束
            @Override
            public void onNetworkFail() {
                super.onNetworkFail();
                view.onNetworkFail();
            }

            //加载中
            @Override
            public void onFinish() {
                super.onFinish();
                view.hideProcessingIndicator();
            }
        });

    }





    @Override
    public void onStart() {
        mService = new OperationService();
    }
}
